<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>

<script type="text/javascript" src="js/jquery.itextclear.js"></script>
<script type="text/javascript">
    $(document).ready(function() {
        $('input[type=text], input[type=password], input[type=url], input[type=email], input[type=number], textarea', '.form').iTextClear();
    });
</script>
<!-- jQplot CSS -->

<link rel="stylesheet" media="screen" href="CSS/Tree.css"/>
<!-- jQplot CSS END -->

<!-- DATATABLES CSS -->
<link rel="stylesheet" media="screen" href="lib/datatables/css/vpad.css"/>
<script type="text/javascript" src="lib/datatables/js/jquery.dataTables.js"></script>
<!--<script type="text/javascript">
    $(document).ready(function() {
        $('#example').dataTable({
            "sPaginationType": "full_numbers"
        });
    });
</script>
-->
<!-- DATATABLES CSS END -->

<h1 class="page-title">账号设置 - 修改</h1>

<div class="container_12 clearfix leading">


    <div class="side grid_12 leading">
        <form class="form has-validation" name="post-form" id="post-form">


            <div class="clear"></div>


            <div class="clearfix">

                <label for="form-name" class="form-label">员工姓名</label>

                <div class="form-input"><input name="user.name" type="text" required="required" id="form-name"
                                               placeholder="Enter your name" value="${user.name}" disabled="disabled"/>
                </div>


            </div>

            <div class="clearfix">

                <label for="form-username" class="form-label">账号 <em>*</em></label>

                <div class="form-input"><input name="user.loginName" type="text" required="required" id="form-username"
                                               placeholder="字母或者数字 (最大12个字符)" value="${user.loginName}" maxlength="12" readonly="readonly"/></div>


            </div>

            <%--<div class="clearfix">
                <label for="password" class="form-label">输入旧密码</label>
                <div class="form-input"><input type="password" id="password" name="old_password" maxlength="30" placeholder="最大30个字符"/></div>
            </div>--%>

            <div class="clearfix">

                <label for="newPassword" class="form-label">创建新密码</label>

                <div class="form-input"><input type="password" id="newPassword" name="new_password" maxlength="30"
                                               placeholder="最大30个字符"/></div>

            </div>

            <div class="clearfix">

                <label for="confirmPassword" class="form-label">新密码创建确认</label>

                <div class="form-input"><input type="password" id="confirmPassword" name="confirm_password"
                                               data-equals="repassword" maxlength="30" placeholder="再次输入密码"/></div>

            </div>

            <div class="form-action clearfix">
                <input type="hidden" name="user.id" value="${user.id}">
                <button class="button" type="button" onclick="checkForm()">修改</button>

                <button class="button" type="reset">重置</button>
                <a class="button" href="#user/setup.xhtml"><span style="background:url(${ctx}/images/img/arrow_undo.png)"
                                                                class="icon">&nbsp;</span>返回</a>

            </div>

        </form>
    </div>
</div>

<div class="clear"></div>


<script type="text/javascript" src="js/Tree.js"></script>

<script type="text/javascript">
    function checkForm(){
        /*if(checkNull($("#password").attr("value"))){
            alert("请输入旧密码");
            return false;
        }*/

        if(checkNull($("#newPassword").attr("value"))){
            alert("请输入新密码");
            return false;
        }

        if(checkNull($("#confirmPassword").attr("value"))){
            alert("请输入新密码确认密码");
            return false;
        }

        if($("#newPassword").attr("value")!=$("#confirmPassword").attr("value")){
            alert("两次密码输入不一致");
            return false;
        }
        var url = "${ctx}/user/user_update.xhtml";
        $.ajax(url, {
            type: "POST",
            data: $("#post-form").serialize(),
            dataType:"json",
            cache:false,
            success:function(data) {
               if(data==null || data=='fail'){
                   alert("更新失败");
               }else if(data=='wrong_password'){
                   alert("旧密码错误");
               }else if(data == "success"){
                   alert("更新成功!");
                   window.location.href='#user/setup.xhtml';
               }
            },
            complete:function() {}
        });
    }
</script>
    